from contextlib import asynccontextmanager
from fastapi import FastAPI

from src.services.prometheus.lifespan import startup_prometheus


@asynccontextmanager
async def lifespan(app: FastAPI):
    """
    Actions to run on app startup
    
    This function uses fastAPI app to store data
    in the state, such as db_engine

    :param FastAPI app: _description_
    :return AsyncGenerator[None, None]: _description_
    """
    # startup
    app.middleware_stack = None
    startup_prometheus(app)
    app.middleware_stack = app.build_middleware_stack()
    
    yield
    
    # shutdown
    